<?php
namespace Admin\Controller;
use Common\Model\LeavelModel;
use Common\Model\UserModel;
use Think\Controller;
use Common\Controller\CommonController;
/**
 * admin 基类控制器
 */
class AdminBaseController extends CommonController{
	/**
	 * 初始化方法
	 */
	public function __construct(){
        parent::__construct();
        $this->return_type='error';
		if(!session('?sys_user')){
			$this->redirect('Login/index');
		}
		$auth=new \Think\Auth();
		$rule_name=CONTROLLER_NAME.'/'.ACTION_NAME;
		$result=$auth->check($rule_name,$_SESSION['sys_user']['userid']);
		if(!$result){
			$this->error('您没有权限访问');
		}
		$this->assign('base_sys_user',$_SESSION['sys_user']);
	}
	/**  
	* 获取等级参数
	 
	 * @version	  v1.0.0 
	 * @copyright  2016-11-11 上午11:12:19
	*/
	protected function getLeavelSys(){
		$M_Leavel=new LeavelModel();
		$leavel=$M_Leavel->getLeavel();
		foreach ($leavel as $k=>$v){
			$res[$v['leavel_id']]=$v;
		}
		return $res;
		
	}
	/**  
	* 获取未锁定币种
	 
	 * @version	  v1.0.0 
	 * @copyright  2016-11-22 上午10:01:47
	*/
	protected function getMoneySys(){
		$where['M_T.is_lock']=0;
		$res=M('Money_type')->alias('M_T')->join('__MONEY_SYS__  M_S on M_T.money_id=M_S.money_id','left')->where($where)->select();
		foreach ($res as $k=>$v){
			$money_sys[$v['money_id']]=$v;
		}
		return $money_sys;
	}
	/**  
	* 获取未锁定币种
	 
	 * @version	  v1.0.0 
	 * @copyright  2016-11-22 上午10:01:47
	*/
	protected function getTakeMoneySys(){
		$where['M_T.is_lock']=0;
		$where['M_T.is_take']=1;
		$res=M('Money_type')->alias('M_T')->join('__MONEY_SYS__  M_S on M_T.money_id=M_S.money_id','left')->where($where)->select();
		foreach ($res as $k=>$v){
			$money_sys[$v['money_id']]=$v;
		}
		return $money_sys;
	}
	protected function findUserByUserId($user_id)
	{
	    $User=UserModel::newSelf();
	    $user_info=$User->findUserByUserId($user_id);
	    $this->notEmptyValidate($user_info,'请正确操作');
	    $user_info['tuiuser']=$User->findUserByUserId($user_info['tui_id']);
	    $user_info['jieuser']=$User->findUserByUserId($user_info['jie_id']);
	    return $user_info;
	}
	protected function findUserByUserName($username)
	{
	    $User=UserModel::newSelf();
	    $user_info=$User->findUserByUsername($username);
	    $this->notEmptyValidate($user_info,'用户不存在');
	    $user_info['tuiuser']=$User->findUserByUserId($user_info['tui_id']);
	    $user_info['jieuser']=$User->findUserByUserId($user_info['jie_id']);
	    return $user_info;
	    
	}
}

